package com.panshi.admin_manage.controller;

import com.panshi.admin_manage.service.impl.AdminService;
import com.panshi.vo.SysAdmin;
import com.panshi.vo.DataResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping(produces = {"application/json;charset=UTF-8"})
public class AdminController {

    @Autowired
    private AdminService adminService;


    @GetMapping("/sys-app/list")
    public DataResult findAdmin(){
        DataResult result = new DataResult();
        result.setData(adminService.list(null));
        log.info("adming-list:{}","查询所有管理员");
        return result;
    }


    @GetMapping("/admin-app/byid/{id}")
    public SysAdmin findAdminById(@PathVariable("id") Integer id){
        log.info("查询adminID:{}",id);
        return adminService.getById(id);
    }


    @PostMapping("/admin-app/add")
    public Boolean add(@Validated SysAdmin adminVO){
        log.info("adming-add:{}","增加管理员");
        return adminService.save(adminVO);
    }


    @PostMapping("/admin-app/upd")
    public Boolean upd(@Validated SysAdmin adminVO){
        log.info("adming-upd:{}","修改管理员");
        return adminService.updateById(adminVO);
    }

    @GetMapping("/admin-app/del/{id}")
    public Boolean del(@PathVariable("id") Integer id){
        SysAdmin adminVO = new SysAdmin();
        adminVO.setId(id);
        adminVO.setAState(-1);
        log.info("adming-del:{}","删除管理员");
        return adminService.updateById(adminVO);
    }

    @ApiOperation("admin-查询所有管理等级")
    @GetMapping("/admin-app/grade")
    public List<SysAdmin> findAdminGrade(){
        return adminService.findAdminGrade();
    }

}
